package com.org.gsc.chartdemo.activitys;
import android.graphics.Color;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.org.gsc.chartdemo.R;
import com.org.gsc.chartdemo.bases.BaseActivity;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by qundui on 2017/8/30.
 * 饼状图页面
 */
public class PieActivity extends BaseActivity {
    private PieChart mPieChart;
    private List<PieEntry> y=new ArrayList<>();
    private PieDataSet dateset=new PieDataSet(y,"冰砖图");
    private PieData mdata=new PieData(dateset);
    @Override
    protected void doBusy() {
        mPieChart= findView(R.id.pc);
//        mPieChart= (PieChart) findViewById(R.id.pc);
        mPieChart.getDescription().setEnabled(false);
        mPieChart.setUsePercentValues(true);
       mPieChart.setExtraOffsets(5, 10, 5, 5);
        mPieChart.setCenterText("我是郭神,我为我自己代言");

//做动画
        mPieChart.animateXY(2000,2000);
       // mPieChart.setDrawHoleEnabled(false);//是否铺满
        mPieChart.setHoleColor(Color.GREEN);//设置内圈的颜色
        mPieChart.setTransparentCircleColor(Color.WHITE);//设置内圈边缘的颜色
        mPieChart.setTransparentCircleAlpha(110);
        mPieChart.setRotationAngle(0);
        mPieChart.setHoleRadius(58f);
        mPieChart.setTransparentCircleRadius(61f);
        //图例设置
        Legend l = mPieChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(false);
        l.setTextColor(Color.GREEN);
        l.setTextSize(12);
        l.setXEntrySpace(7f);
        l.setYEntrySpace(0f);
        l.setYOffset(0f);
        y.add(new PieEntry(0.1f,"第1个饼子"));
        y.add(new PieEntry(0.5f,"第2个饼子"));
        y.add(new PieEntry(0.2f,"第3个饼子"));
        y.add(new PieEntry(0.1f,"第4个饼子"));
        y.add(new PieEntry(0.1f,"第5个饼子"));
        //设置外面显示Values
        dateset.setValueLinePart1OffsetPercentage(80.f);
        dateset.setValueLinePart1Length(0.2f);
        dateset.setValueLinePart2Length(0.4f);
        dateset.setValueLineColor(Color.RED);
        dateset.setValueTextColor(Color.BLACK);
        dateset.setValueTextSize(20);
        //dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        dateset.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

       dateset.setColors(ColorTemplate.MATERIAL_COLORS);
       dateset.setSelectionShift(5f);
        dateset.setSliceSpace(3f);//各个饼状图之间空白间隙
        mdata.setValueFormatter(new PercentFormatter());
        mPieChart.setData(mdata);
        mPieChart.invalidate();

    }
    @Override
    protected int getLayoutId() {
        return R.layout.act_pie;
    }
}
